﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using MYNAMESPACE;
namespace final_project
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length == 0 || textBox2.Text.Length == 0)
            {

                MessageBox.Show("must have value");
                this.Close();

            }
            else
            {
                user us = new user();
                us.setnational_id(Int32.Parse(textBox1.Text));
                us.setpassword(string.Format(textBox2.Text));
                //int a = Int32.Parse(textBox1.Text);
                //string b = string.Format(textBox1.Text);

                SqlCommand cm;
                SqlDataReader dr;
                SqlConnection cn = new SqlConnection(@"Data Source =PC; Initial Catalog =Bank_test ;Integrated Security= True; ");
                cn.Open();
                cm = new SqlCommand("select id,pass  from userdata where id= '" + us.getnational_id() + "' and pass='" + us.getpassword() + "' ", cn);
                dr = cm.ExecuteReader();
                int count = 0;
                while (dr.Read())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    this.Hide();
                    Account ACC = new Account();
                    // MessageBox.Show("correct");
                    ACC.passvalue = textBox1.Text;
                    ACC.ShowDialog();   //.passvalue = textBox2.Text; 



                }
                else
                {
                    MessageBox.Show("not correct");

                }
                cn.Close();



            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Hide();
            CreateAccount CA = new CreateAccount();

            CA.ShowDialog();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
          
        }
    }
}
